﻿
@{
    ViewBag.Title = "NursingInput";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/wdtree/tree.js")"></script>
<link href="@SiteUrl.GetStaticResourceScriptUrl("~/js/wdtree/tree.css")" rel="stylesheet" />
<style>
    .form .formTitle {
        width: 80px;
        padding-right: 5px;
    }

    .radio input[type=radio], .radio-inline input[type=radio] {
        margin-left: -16px;
    }

    .radio-inline {
        line-height: 22px;
        margin-left: 30px;
        width: 35px;
    }

    .ui-th-ltr, .ui-jqgrid .ui-jqgrid-htable th.ui-th-ltr {
        border: solid 1px #ddd;
    }

        .ui-th-ltr div, .ui-jqgrid .ui-jqgrid-htable th.ui-th-ltr div {
            text-align: center;
        }

    .ui-jqgrid .ui-jqgrid-btable tbody tr.jqgrow td {
        border: solid 1px #ddd;
    }

    .ui-jqgrid .table-bordered th {
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .dv-left {
        width: 200px;
        float: left;
    }

    .dv-left-tree {
        overflow-y: auto;
        border-radius: 4px;
        background: white;
    }

    .dv-left-title {
        padding: 6px 10px;
        border-bottom: 1px solid transparent;
        border-top-left-radius: 3px;
        border-top-right-radius: 3px;
        border-color: #ddd;
        background-color: white;
    }

    .dv-right {
        float: left;
        margin-left: 5px;
    }

    .dv-right-order {
        width: 100%;
    }
</style>
<div class="dv-body">
    <div class="dv-left">
        <div class="panel panel-default">
            <div class="panel-heading navb-bg">
                筛选条件
            </div>
            <table class="form" style="width:95%">
                <tbody>
                    <tr>
                        <th class="formTitle">姓名/住院号：</th>
                        <td class="formValue">
                            <input id="keyword" type="text" onblur="getPatTreeList()" class="form-control">
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">在院状态：</th>
                        <td class="formValue formDdlSelectorTd">
                            <select class="form-control" id="zyzt">
                                <option value="">全部</option>
                                <option value="zy" selected>在院</option>
                                <option value="cy">出院</option>
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="dv-left-title">
            患者列表
        </div>
        <div class="dv-left-tree" id="PatTreeList"></div>
    </div>
    <div class="dv-right">
        <div class="topPanel" style="height:50px;line-height:30px">
            <table class="form">
                <tr>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                </tr>
                <tr>
                    <td class="formTitle"><span class="required">*</span>日期：</td>
                    <td class="formValue">
                        <input id="rq" name="rq" type="text" class="required form-control input-wdatepicker formClearIgnore">
                    </td>
                    <td class="formTitle sjd"><span class="required">*</span>时间点：</td>
                    <td class="formValue sjd" colspan="3">
                        <div>
                            <label class="radio-inline">
                                <input type="radio" name="optionsSj" value="2">2
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="optionsSj" value="6" checked>6
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="optionsSj" value="10">10
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="optionsSj" value="14">14
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="optionsSj" value="18">18
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="optionsSj" value="22">22
                            </label>
                        </div>
                    </td>
                    @*<td class="formTitle"><span class="required">*</span>病区：</td>
                    <td class="formValue">
                        <select id="WardCode" class="form-control">
                            <option>
                                全部
                            </option>
                        </select>
                    </td>*@
                </tr>
            </table>
        </div>
        <div class="gridPanel">
            <table id="gridList"></table>
        </div>
        <div style="width:30%"><span style="color:red">说明：</span>血压测量单位：mmHg；摄入摄出测量单位：ml</div>
    </div>
</div>

@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 4, 8 },
    F8Text = "提交"
})
<script type="text/javascript">
    var localdata = [];
    var errmsg = "";
    var searchsjd = "";
    var patzyh = "";
    $(function () {
            $(window).resize(function () {//浏览器窗口调整大小时重新计算宽高
                $(".dv-body").height($(window).height());
                $(".dv-body").width($(window).width());
            });
            var rightWidth = $(".Newtouch_iframe", parent.document).width() - $(".dv-left").width() - 30;
            $(".dv-right").width(rightWidth);

        if ('@ViewBag.MutipatientNursingInputFlag' == '0') {
            $('#rq').val('@DateTime.Now.ToString("yyyy-MM-dd")').focus(function () { WdatePicker({ dateFmt: 'yyyy-MM-dd', onpicked: function () { btn_search() } })});
            searchsjd = $("[name=optionsSj]:checked").val();
        } else {
            $('#rq').val('@DateTime.Now.ToString("yyyy-MM-dd HH:00:00")').focus(function () { WdatePicker({ dateFmt: 'yyyy-MM-dd HH:00:00', onpicked: function () { btn_search() } }) });
            $('.sjd').css("display","none");
            searchsjd = new Date($.trim($('#rq').val())).getHours();
        }

        gridList();
        $("#gridList").jqGrid('setFrozenColumns');
        getPatTreeList();
        $('#zyzt').change(function () {
            getPatTreeList();
        });
    })
        function getPatTreeList() {
            $("#PatTreeList").treeview({
                height: $(window).height() - 150,
                slimscroll: false,
                showcheck: true,
                url: "/NurseManage/InpatientVitalSigns/GetPatWardTree?zyzt=" + $('#zyzt').val() + "&keyword=" + $('#keyword').val(),
                onnodeclick: function (item) {
                },
                oncheckboxclick: function (item, s) {
                    patzyh = "";
                    getOrderTWDList(item, s);
                }
            });

    }
    function getOrderTWDList(item,s) {
        var patlist = $("#PatTreeList").getCheckedNodeObjArray();
        var patlistFath = "";
        yjjzhmsg = "";

        //当前选中父节点
        var len = 0;
        var single = 0; //是否单个子节点

        if (item != null && item.Ex1 == "p") {
            patlistFath = item.ChildNodes;
            len = patlistFath.length;
        }
        else if (item != null && item.Ex1 == "c") {
            patlistFath = item;
            len = 1;
            single = 1;
        }

        //选中节点
        for (var i = 0; i < patlist.length; i++) {
            if (patlist[i].Ex1 == "c") {
                patzyh += patlist[i].value + ",";
            }
        }

        if (s == 1) {
            if (single == 0) {
                for (var j = 0; j < len; j++) {
                    if (patlistFath[j].Ex1 == "c") {
                        patzyh += patlistFath[j].value + ",";
                    }
                }
            }
            else if (patlistFath.Ex1 == "c") {
                patzyh += patlistFath.value;
            }
        }
        else if (s == 0) {
            if (single == 0) {
                for (var j = 0; j < len; j++) {
                    if (patlistFath[j].Ex1 == "c" && patlistFath[j].checkstate == 1) {
                        patzyh = patzyh.replace(patlistFath[j].value + ",", "");
                    }
                }
            }
            else if (patlistFath.Ex1 == "c") {
                patzyh = patzyh.replace(patlistFath.value + ",", "");
            }

        }
        if (patzyh != null && patzyh != "") {
            $.najax({
                url: "@Url.Action("GetNursingInputGridJson")",
                dataType: "json",
                data: { bq: "", sj: searchsjd, rq: $.getDate({ date: $.trim($('#rq').val()) }), zyh: patzyh },
                type: "POST",
                success: function (data) {
                    localdata = data;
                    $("#gridList").clearGridData(); //先清
                    $("#gridList").jqGrid('setGridParam', {
                        datatype: 'local',
                        data: localdata,
                    }).trigger("reloadGrid");

                }
            });
        } else {
            $("#gridList").clearGridData(); //先清
        }
        //$('#gridList').jqGrid('setGridParam', {
        //    postData: {
        //        patList: patzyh, zxsj: $('#txt_zxrq').val() + " " + $('#txt_yzxsj').val()
        //    }
        //}).trigger("reloadGrid");
    }
    function btn_search() {
        if (patzyh != null && patzyh!="") {
        if ('@ViewBag.MutipatientNursingInputFlag' == '0') {
            searchsjd = $("[name=optionsSj]:checked").val();
        } else {
            searchsjd = new Date($.trim($('#rq').val())).getHours();
        }
        if (validate()) {
            loadgridjson("", searchsjd);
            }
        }
    }

    $('input[name="optionsSj"]').click(function ()
    {
        btn_search();
    });

    function loadgridjson(bqval, searchsjd) {
        $.najax({
            url: "@Url.Action("GetNursingInputGridJson")",
            dataType: "json",
            data: { bq: bqval, sj: searchsjd, rq: $.getDate({ date: $.trim($('#rq').val()) }), zyh: patzyh },
            type: "POST",
            success: function (data) {
                localdata = data;
                $("#gridList").clearGridData(); //先清
                $("#gridList").jqGrid('setGridParam', {
                    datatype: 'local',
                    data: localdata,
                }).trigger("reloadGrid");

            }
        });
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.jqGrid({
            datatype: 'local',
            data: localdata,
            rowNum:1000,
            height: $(window).height() - 190,
            shrinkToFit: false,   //true:按比例初始化列宽度 false:使用colModel指定的宽度
            autowidth: true,
            rownumbers: true,  //是否显示序号
            editurl: "clientArray",  //行编辑不向服务器提交数据
            multiselect: true,//复选框
            unwritten: false,
            autoScroll: false,//当autoScroll和shrinkToFit均为false时，会出现行滚动条
            shrinkToFit: false,//是否列宽度自适应。true=适应 false=不适应
            colModel: [
                { label: "Id", name: "Id", hidden: true, frozen: true },
                { label: "住院号", name: "zyh", width: 50, align: 'left', frozen: true },
                { label: "病人姓名", name: "xm", width: 50, align: 'left', frozen: true },
                { label: "状态", name: "brzt", hidden: true, editable: true },
                {
                    label: "状态", name: "brzttext", width: 80, align: 'left', edittype: "select", editwidth: "75%", editable: true, editoptions: {
                        dataEvents: [
                            {
                                type: 'change',
                                fn: function (e) {
                                    var row = $(e.target).closest('tr.jqgrow');
                                    var rowid = row.attr('id');
                                    //用作保存选中的值
                                    $("#" + rowid + "_brzt").val($(this).val());
                                }
                            }
                        ]
                    }
                },
                { label: "状态标注<br />(时)", name: "brzt_hh", width: 80, align: 'left', editable: true },
                { label: "状态标注<br />(分)", name: "brzt_mi", width: 80, align: 'left', editable: true},
                {
                    label: "<span class='required'>*</span>体温测量方式", required: true, name: "twclfstext", width: 80, align: 'left', edittype: 'select', editwidth: "65%", editable: true, editoptions: {
                        value: { 1: '口温', 2: '腋温', 3: '肛温' },
                        dataEvents: [
                            {
                                type: 'change',
                                fn: function (e) {
                                    var row = $(e.target).closest('tr.jqgrow');
                                    var rowid = row.attr('id');
                                    //用作保存选中的值
                                    $("#" + rowid + "_twclfs").val($(this).val());
                                }
                            }
                        ]
                    }
                },
                { label: "twclfs", name: "twclfs", hidden: true, editable: true },
                { label: "<span class='required'>*</span>体温(℃)", editwidth: "75%", required: true, name: "tw", width: 50, align: 'left', editable: true },
                { label: "起搏器", name: "qbq", width: 65, align: 'left', editwidth: "75%", editable: true},
                { label: "呼吸机", name: "hxj", width: 65, align: 'left', editwidth: "75%", editable: true},
                { label: "心率(次/分)", name: "xl", width: 65, align: 'left', editwidth: "75%", editable: true },
                { label: "脉搏(次/分)", name: "mb", width: 65, align: 'left', editwidth: "75%", editable: true },
                { label: "呼吸(次/分)", name: "hx", width: 65, align: 'left', editwidth: "75%", editable: true },
                { label: "hxj", name: "hxj", width: 50, align: 'left', hidden: true },
                {label: "血压上值", name: "xysz", width: 50, align: 'left', editable: true},
                { label: "血压下值", name: "xyxz", width: 50, editable: true, align: 'left'},
                { label: "体重(kg)", name: "tz", width: 50, align: 'left', editable: true },
                { label: "身高(cm)", name: "sg", width: 50, align: 'left', editable: true },
                { label: "测量说明", name: "tzclbz", width: 100, align: 'left', editwidth: "75%", editable: true },
                { label: "疼痛评分", name: "ttpf", width: 50, align: 'left', editable: true },
                { label: "大便次数", name: "dbcs", width: 50, align: 'left', editable: true },
                { label: "说明", name: "dbcsbz", width: 80, align: 'left', editwidth: "75%", editable: true },
                { label: "过敏药", name: "gmyw", width: 80, align: 'left', editable: true },
                { label: "总入量", name: "zrl", width: 50, align: 'left', editable: true },
                { label: "总出量", name: "zcl", width: 50, align: 'left', editable: true },
                { label: "引流量", name: "yll", width: 50, align: 'left', editable: true },
                { label: "输液量", name: "syl", width: 50, align: 'left', editable: true },
                { label: "饮食量", name: "ysl", width: 50, align: 'left', editable: true },
                { label: "输血量", name: "sxl", width: 50, align: 'left', editable: true },

                { label: "呕吐量", name: "otl", width: 50, align: 'left', editable: true },
                { label: "尿量", name: "xbl", width: 40, align: 'left', editable: true },
                { label: "超液量", name: "cys", width: 50, align: 'left', editable: true },
                { label: "伤口引流", name: "skyll", width: 50, align: 'left', editable: true },
                { label: "胸液量", name: "xyl", width: 50, align: 'left', editable: true },
                { label: "胃液量", name: "wyl", width: 50, align: 'left', editable: true},
                { label: "负吸小球", name: "fxxq", width: 50, align: 'left', editable: true},
                { label: "其他摄出", name: "qtsc", width: 50, align: 'left', editable: true},
                { label: "吸氧/流量L/min", name: "xyll", width: 90, align: 'left', editwidth: "75%", editable: true},
                { label: "吸氧说明", name: "xyfs", width: 100, align: 'left', editwidth: "75%", editable: true },
                { label: "血氧饱和度", name: "xybhd", width: 80, align: 'left', editwidth: "75%", editable: true}],
            viewrecords: true,
            rownumbers: false,
            editinputwidthborder: false,    //是否需要边框 默认为true
            editinputborderradius: false,   //是否需要边框圆角 默认true（有圆角）
            gridComplete: function () {
                EnableInlineEditBox();
            }
        });

        //二级菜单
        $gridList.jqGrid('setGroupHeaders', {
            useColSpanStyle: true,
            groupHeaders: [
                {
                    startColumnName: 'syl',
                    numberOfColumns: 3,
                    titleText: '摄入量'
                },
                {
                    startColumnName: 'otl',
                    numberOfColumns: 8,
                    titleText: '摄出量'
                }
            ]
        });
        
    }

    function EnableInlineEditBox() {
        var ids = $("#gridList").getDataIDs();
        $.each(ids, function () {
            var rowid = String(this);
            //打开编辑模式
            $("#gridList").jqGrid('editRow', rowid, false, initInlineFunc);
        });
    }

    function initInlineFunc(rowid) {
        var currenttwclfs = $("#" + rowid + "_twclfs").val();
        $("#" + rowid + "_twclfstext").val(currenttwclfs);
        if (currenttwclfs=="") {
            $("#" + rowid + "_twclfstext").val('2');
            $("#" + rowid + "_twclfs").val('2');
        }
        //病人状态下拉框
        $("#" + rowid + "_brzt").parent().next().children('select').html('');
        var currentbrzt = $("#" + rowid + "_brzt").val();
        if (top.clients.enums) {
            var option = "<option>请选择</option>";
            $.each(top.clients.enums, function (i,v) {
                if (v.Type === "EnumHlbrzt") {
                    $.each(v.Items, function (ii, vv) {
                        if (currentbrzt == vv.Value) {
                            option += '<option value="' + vv.Value + '" selected>' + vv.Desc + '</option>';
                        } else {
                            option += '<option value="' + vv.Value + '">' + vv.Desc + '</option>';
                        }
                    });
                }
            });
            $("#" + rowid + "_brzt").parent().next().children('select').append(option);
        }

        bindItemFloator(rowid + "_tzclbz", "WeightMemo");
        //bindItemFloator(rowid + "_dbcsbz", "DefecationFreqMemo");
        bindItemFloator(rowid + "_xyfs", "OxygenUptakeMed");

    }

    function bindItemFloator(inputId, itemType) {
        //绑定字典
        $("#" + inputId).newtouchFloatingSelector({
            height: 200,
            width: 330,
            clickautotrigger: true,
            filter: function (keyword) {
                return $.itemDetails.getItems(itemType);
            },
            colModel: [
                { label: '编码', name: 'Code', widthratio: 20 },
                { label: '名称', name: 'Name', widthratio: 60 },
            ],
            itemdbclickhandler: function ($thistr, $thisinput) {
                //保存时验证val和data-Name一致
                $thisinput.attr('data-Code', $thistr.attr('data-Code'));
                $thisinput.attr('data-Name', $thistr.attr('data-Name'));
                $thisinput.val($thistr.attr('data-Name'));
            }
        });
    }


    function presubmit() {
        headdata = validate();
        if (headdata) {
            //获取所有行Id，遍历使编辑框处于保存状态
            var rowIds = $("#gridList").jqGrid("getGridParam", "selarrrow");
            var validationFailedArr = [];
            for (var i = 0; i < rowIds.length; i++) {
                var saveResult = $("#gridList").saveRow(rowIds[i], null, null, null, function (callbackRowId) { }, null, null);
                var rowData = $("#gridList").jqGrid('getRowData', rowIds[i]);
                if (!validaterow(rowData)) {
                    validationFailedArr.push(rowIds[i]);
                }
            }
            if (validationFailedArr != null && validationFailedArr.length > 0) {
                for (var i = 0; i < validationFailedArr.length; i++) {
                    $("#gridList").jqGrid('editRow', validationFailedArr[i], false, initInlineFunc);//打开编辑模式
                }
                $.modalAlert(errmsg, "warning");
                return;
            }
            var gridData = $("#gridList").jqGrid('getRowData_AllLine', true, true);
            if (gridData.length < 1) {
                $.modalAlert("缺少选中数据", 'warning');
                return;
            }
            var submitdata = { entityList: gridData, sjd: headdata.sjd, rq: headdata.rq,flag:'@ViewBag.MutipatientNursingInputFlag' };
            return submitdata;
        }
    }
    //F8提交至服务器
    function newtouch_event_f8() {
        submitdata = presubmit();
        if (submitdata) {
            $.submitForm({
                url: "@Url.Action("submitmutiple")",
                param: submitdata,
                success: function () {
                    btn_search();
                }
            })
        }
    }

    function validate() {
        var headdata = {};
        var selectrq = $.trim($('#rq').val())
        headdata.rq = selectrq.substr(0, 10);
        if (headdata.rq== '') {
            $.modalAlert("请选择日期", "warning");
            return false;
        }

        if ('@ViewBag.MutipatientNursingInputFlag' == '0') {
            headdata.sjd = $("[name=optionsSj]:checked").val() || null;
            if (!(headdata.sjd == "2" || headdata.sjd == "6" || headdata.sjd == "10" || headdata.sjd == "14"
                || headdata.sjd == "18" || headdata.sjd == "22")) {
                $.modalAlert("请选择时间点", "warning");
                return false;
            }
        } else {
            headdata.sjd = new Date($.trim($('#rq').val())).getHours();
        }
        return headdata;
    }

    function validaterow(rowdata) {
        //1. 体温测量方式
        if (!rowdata.twclfs) {
            //$.modalAlert(rowdata.xm+"缺少体温测量方式", "warning");
            errmsg += rowdata.xm + "缺少体温测量方式;";
            return false;
        }
        //2. 体温
        if (!rowdata.tw) {
            //$.modalAlert(rowdata.xm +"缺少体温", "warning");
            errmsg += rowdata.xm + "缺少体温测量方式;";
            return false;
        }
        return true;
    }
</script>

